2015/8/9
ggmap is a new tool which enables such visualization by combining with GoogleMaps, Openstreet … etc.
Besides, ggmap can combine with the powerful visualization packege, ggplot2, which allow us to extent the applications of geographic visualization. ex: geom_path …
library(ggmap)
qmap 為 get_map 和 ggmap 的快速指令
qmap(location = "台北車站", zoom = 14, source = "google")
qmap(location = "政治大學", zoom = 14, source = "osm")
# it's the same map <- get_map(location = '台北車站',zoom = 14, source= 'google') ggmap(map, fullpage=T)
Download Dataset from Here and load it in
library(RCurl)
url <- getURI('https://raw.githubusercontent.com/unityculture/20150809_GeoViz_Tutorial/master/hsinchu.csv')
data <- read.csv(text = url)
土地面積 建物面積 屋齡 房屋樓層 車位數目 有無管理 時間序列 單價_坪
1: 13.37 15.90847 23 16 1 1 1 163434.7
2: 26.68 43.79595 2 11 1 1 1 123517.4
3: 29.13 48.39697 2 11 1 1 1 121494.2
4: 11.08 34.20972 20 12 0 1 1 105233.1
5: 38.96 97.03595 4 14 1 1 1 252482.6
6: 27.95 49.85200 2 11 2 1 1 129173.6
lon lat road.name price.level
1: 120.9775 24.81635 新竹市新竹巿田美三街48巷1~30號 15~20W
2: 120.9395 24.79717 新竹市新竹巿牛埔南路142巷33弄1~30號 10~15W
3: 120.9395 24.79720 新竹市新竹巿牛埔南路142巷33弄1~30號 10~15W
4: 120.9599 24.79710 新竹市新竹巿中華路三段121~150號 10~15W
5: 120.9693 24.81003 新竹市新竹巿北大路91~120號 >25W
6: 120.9393 24.79739 新竹市新竹巿牛埔南路142巷33弄1~30號 10~15W
hs.map <- qmap(location='新竹市',zoom=13,source='google')
hs.map + geom_point(data=data,
aes(x=lon, y=lat))
馬偕紀念醫院新竹院區hs.map <- qmap(location='馬偕紀念醫院新竹院區',zoom=13,source='google',color='bw')
hs.map + geom_point(data=data,
aes(x=lon, y=lat, color='darkred'),alpha=0.2) +
guides(color='none') # 為了不要讓圖例出來
hs.map + geom_point(data=data,
aes(x=lon, y=lat,
color=price.level,fill=price.level))
hs.map +
geom_point(data=data,aes(x=lon, y=lat,size=price.level,color='darkred'),alpha=0.2) +
guides(color='none')
有時候單純想知道哪一些區域是相對密集時也可以考慮這種呈現方式
一樣可以透過顏色來區分密度、或是價格資訊
hs.map + stat_bin2d(aes(x = lon, y = lat), bins = 10, alpha = 1/2,data = data)
hs.map + stat_bin2d(aes(x = lon, y = lat, fill=price.level),bins = 30, alpha = .2, data = data)
hs.map +
stat_density2d(
aes(x = lon, y = lat, fill = ..level..,
alpha = ..level..),size=.01, bins = 16, data = data,
geom = "polygon")+
scale_fill_gradient(low = "yellow", high = "red")+
scale_alpha(range = c(0.00, 0.25), guide = FALSE)